<?xml version='1.0' encoding='UTF-8' ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:c="http://java.sun.com/jsp/jstl/core">

    <!--Inicia la composicion de la pagina en la plantilla-->
    <ui:composition template="/resource/template/plantilla.xhtml">

        <!--Segmento que define el contenido del header-->
        <ui:define name="head">
            <h:head>
                <f:loadBundle basename="person.academy.label_#{logged.loggedIdiom}" var="label" />
                <f:loadBundle basename="person.academy.message_#{logged.loggedIdiom}" var="message" />
                <f:loadBundle basename="person.academy.help_#{logged.loggedIdiom}" var="help" />
                <script>
                    function verificar(dato)
                    {
                        var agree = confirm(dato);
                        if (agree)
                            return true;
                        else
                            return false;
                    }
                </script>
            </h:head>
        </ui:define>

        <!--Segmento que define el contenido de la pagina-->
        <ui:define name="content">
            <h:body>
                <h:outputText value="#{message.m0}" class="label" rendered="#{!access.visit}"/>
                <h:form rendered="#{access.visit}">  
                    <p:growl id="messages" showDetail="true"/>  
                    <h:panelGroup>
                        <!--PAIS -->
                        <div class="field">
                            <h:outputText value="#{label.field3}" class="label"/>
                            <h:selectOneMenu id="pais" value="#{person_academy.id_pais}" required="#{param['required']=='true'}" requiredMessage="#{message.m22}">
                                <f:selectItem itemLabel="" itemValue=""/>
                                <f:selectItems value="#{location_countryFind.listItem()}"/>  
                            </h:selectOneMenu>
                            <h:commandButton id="btnPais" class="addButton" onclick="addPais.show();" type="button"/>
                            <!--Dialogos para la insertcion de pais-->
                            <p:dialog id="addPais" widgetVar="addPais" header="#{label.title2}" modal="true" resizable="false">
                                <h:inputText value="#{person_location.countryBeans.nombre}" class="textfield"/>
                                <h:commandButton value="#{label.button1}" class="button" actionListener="#{person_location.insertCountry}" onclick="addPais.hide();"/>
                            </p:dialog>
                            <h:outputText class="required" value="*"/>
                        </div>

                        <!--NIVEL -->
                        <div class="field">
                            <h:outputText value="#{label.field2}" class="label"/>
                            <h:selectOneMenu value="#{person_academy.idl_nivel}" required="#{param['required']=='true'}" requiredMessage="#{message.m22}">  
                                <f:selectItem itemLabel="" itemValue=""/> 
                                <f:selectItem itemLabel="#{label.nivel1}" itemValue="1"/> 
                                <f:selectItem itemLabel="#{label.nivel2}" itemValue="2"/> 
                                <f:selectItem itemLabel="#{label.nivel3}" itemValue="3"/> 
                                <f:selectItem itemLabel="#{label.nivel4}" itemValue="4"/>
                                <f:selectItem itemLabel="#{label.nivel5}" itemValue="5"/> 
                                <f:selectItem itemLabel="#{label.nivel6}" itemValue="6"/> 
                                <f:selectItem itemLabel="#{label.nivel7}" itemValue="7"/>
                            </h:selectOneMenu>
                            <h:outputText styleClass="required" value="*"/>
                        </div>

                        <!--FECHA DE INICIO -->
                        <div class="field">
                            <h:outputText value="#{label.field7}" class="label"/>
                            <p:calendar value="#{person_academy.inicio}" effect="slide" navigator="true" readonlyInput="true" pattern="dd/MM/yy" yearRange="c-82:c+10" size="5"/>
                            <h:outputText class="required" value="*"/>
                        </div>

                        <!--FECHA DE FIN -->
                        <div class="field">
                            <h:outputText value="#{label.field8}" class="label"/>
                            <p:calendar value="#{person_academy.fin}"  effect="slide" navigator="true" readonlyInput="true" pattern="dd/MM/yy" yearRange="c-82:c+10" size="5"/>
                            <h:outputText class="required" value="*"/>
                        </div>
                        <!--INSTITUCION -->
                        <div class="field">
                            <h:outputText value="#{label.field6}" class="label"/> 
                            <h:inputText id="institucion" class="textfield" value="#{person_academy.institucion}" size="50" maxlength="200" required="#{param['required']=='true'}" requiredMessage="#{message.m24}"/>
                            <h:outputText class="required" value="*"/>
                        </div>
                        <!--TITULO -->
                        <div class="field">
                            <h:outputText value="#{label.field4}" class="label"/> 
                            <h:inputText id="titulo" class="textfield" value="#{person_academy.titulo}" size="50" maxlength="200" required="#{param['required']=='true'}" requiredMessage="#{message.m23}"/>
                            <h:outputText class="required" value="*"/>
                        </div>
                        <!--ESPECIALIDAD -->
                        <div class="field">
                            <h:outputText value="#{label.field5}" class="label"/> 
                            <h:inputText id="especialidad" class="textfield" value="#{person_academy.especialidad}" size="50" maxlength="200"/>
                        </div>
                    </h:panelGroup>
                    <!--INSERTAR -->
                    <h:commandButton value="#{label.button1}" class="button" actionListener="#{person_academy.insert}" rendered="#{access.add}" onclick="return verificar('#{message.m7}')">
                        <f:param name="required" value="true"/>
                    </h:commandButton>
                    <!--ACTUALIZAR -->
                    <h:commandButton value="#{label.button2}" class="button" actionListener="#{person_academy.update}" rendered="#{access.update}" onclick="return verificar('#{message.m8}')">
                        <f:param name="required" value="true"/>
                    </h:commandButton>
                    <!--ELIMINAR -->
                    <h:commandButton value="#{label.button3}" class="button" actionListener="#{person_academy.delete}" rendered="#{access.delete}" onclick="return verificar('#{message.m9}')"/>
                    <!--LIMPIAR -->
                    <h:commandButton value="#{label.button4}" class="button" actionListener="#{person_academy.clear}"/>
                    <br/>
                </h:form> 
                <h:form>
                    <c:set var="list" value="#{person_academyFind.listByLoggedId}"/>
                    <h:panelGroup layout="block" class="tableWrapper" rendered="#{not empty list}">
                        <h:dataTable  var="p"  value="#{list}" class="dataTable">
                            <h:column>
                                <h:commandLink styleClass="editButton" actionListener="#{person_academy.selectedTempId(p.id)}"/>
                            </h:column>
                            <h:column >
                                <f:facet name="header">#{label.field2}</f:facet>
                                <c:set var="nivel" value="nivel#{p.idl_nivel}" />
                                <h:outputText value="#{label[nivel]}"/>
                            </h:column>
                            <h:column>  
                                <f:facet name="header">#{label.field4}</f:facet> 
                                <h:outputText value="#{p.titulo}"/>
                            </h:column>
                            <h:column>  
                                <f:facet name="header">#{label.field5}</f:facet> 
                                <h:outputText value="#{p.especialidad}"/>
                            </h:column>
                            <h:column>  
                                <f:facet name="header">#{label.field6}</f:facet> 
                                <h:outputText value="#{p.institucion}"/>
                            </h:column>
                            <h:column>  
                                <f:facet name="header">#{label.field3}</f:facet> 
                                <h:outputText value="#{p.countryBeans.nombre}"/>
                            </h:column>
                            <h:column>  
                                <f:facet name="header">#{label.field7}</f:facet> 
                                <h:outputText value="#{p.inicio}">
                                    <f:convertDateTime type="date" pattern="MM/yyyy"/>
                                </h:outputText>
                            </h:column>
                            <h:column>  
                                <f:facet name="header">#{label.field8}</f:facet>  
                                <h:outputText value="#{p.fin}">
                                    <f:convertDateTime type="date" pattern="MM/yyyy"/>
                                </h:outputText>
                            </h:column>
                        </h:dataTable>
                    </h:panelGroup>
                </h:form>
            </h:body>
        </ui:define>

        <!--Segemento donde se define un texto de ayuda para que el usuario pueda utilizar el formulario del contenido-->
        <ui:define name="slideHelper">
            <h3>#{help.title1} </h3>
            #{help.detail1a}
            <p>
                #{help.title2}
                <ul>
                    <li>#{help.detail2a}</li>
                    <li>#{help.detail2b}</li>
                </ul> 
                #{help.title3}
                <ul>
                    <li>#{help.detail3a}</li>
                    <li>#{help.detail3b}</li>
                </ul>
            </p>
        </ui:define>
    </ui:composition>
</html>
